<?php
/* UltraMemo Project - Quiz_AddQuestion.php
 *   add a question to a gdoc spreadsheet
 * 11/24/09 initial creation
 *
 * @author Scott Szretter
 */

require_once('../PrivateData.php');
require_once('GData.php');
$GData = new GData();
$GData->GDataUser = $user; //from privatedata.php
$GData->GDataPass = $pass; //from privatedata.php
$GData->GDataAuthenticate();
$GData->GDataSSKey=$sheetKey; //from privatedata.php
$GData->GDataWkShtID=$worksheetKey; //from privatedata.php

$aTopics = $GData->getUniqueTopics(); 
$topicHTSelect='<select onChange="document.getElementById(\'t\').value = this.options[this.selectedIndex].value;">';
$topicHTSelect.= '<option value=""></option>';
foreach($aTopics as $Topic) {
    $topicHTSelect.= '<option value="'.$Topic.'">'.$Topic.'</option>';
}
$topicHTSelect.="</select>";


if(isset($_POST['q']) && isset($_POST['a'])) //they are passing a question and answer
{
    $rowArray['qid'] = uniqid();
    $rowArray['topicdesc'] = $_POST['t'];
    $rowArray['question'] = $_POST['q'];
    $rowArray['hint'] = $_POST['h'];
    $rowArray['answer'] = $_POST['a'];
    $rowArray['leitnerbox'] = "1";
    $rowArray['nextreviewdt']=date("m/d/Y H:i:s",strtotime("+1 day"));
    $wasAdded=$GData->listInsertAction($rowArray);

    if($wasAdded) echo "Question Added.<br>";
    else echo "Error - Question was not added!";
} // isset qid and ans
//display question add form
?>
<form method="POST">
    Question:<input type="text" id="q" name="q">*<br>
    Answer:<input type="text" id="a" name="a">*<br>
    Hint:<input type="text" id="h" name="h"><br>
    Topic:<input type="text" id="t" name="t"><?=$topicHTSelect?><br>
    <input type="submit" name="add" id="add" value="add">
</form>

